<?php
namespace app\controllers;

use app\model\guestbookModel;

class IndexController extends \core\mphp
{
    public function index()
    {
        $model = new guestbookModel();
        $data = $model->all();
        $this->assign('data', $data);
        $this->display('index.html');
    }

    public function add()
    {
        $this->display('add.html');
    }

    public function save()
    {
        $data['title'] = post('title');
        $data['content'] = post('content');
        $data['createtime'] = time();
        $model = new guestbookModel();
        $res = $model->addOne($data);
        if($res){
            jump('/');
        } else {
            p('error');
        }
    }

    public function del()
    {
        $id = get('id', 0, 'int');
        if($id){
            $model = new guestbookModel();
            $res = $model->delOne($id);
            if($res){
                jump('/');
            } else {
                exit('删除失败');
            }
        } else {
            exit('参数错误');
        }
    }
}